#!/usr/bin/env ruby
# -*- ruby -*-

require 'common'
require 'open-uri'

url = 'http://developer.rdio.com/docs/read/rest/types'
puts 'module Rdio'
type = nil
open(url).read.split(/\n/).each do |line|
  line.scan />(\w+)<\/h2>/ do |res|
    if type
      puts '  end'
    end
    type = res[0]
    puts
    puts "  class #{type}Data < BaseObj"
    puts "    def initialize(api)"
    puts "      super api"
    puts "    end"
    puts
  end
  line.scan /<dt>(\w+)<\/dt>\s*<dd>([^<]+)<\/dd>/ do |res|
    attr,comment = res
    if attr != 'key'
      puts "    # #{comment}"
      puts "    attr_accessor :#{camel2underscores attr}"
      puts
    end
  end
end
puts '  end'
puts
puts 'end'
